package io.github.biezhi.wechat.voice;

import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.util.Util;
import org.json.JSONObject;

import java.io.IOException;

/**
 * @author wangsh
 * @date 2019-07-05 11:53
 */
public class Sample {

    //设置APPID/AK/SK
    public static final String APP_ID = "16719047";
    public static final String API_KEY = "DGGTBziZ1VaZ0XaYeGuSNzNm";
    public static final String SECRET_KEY = "ZGrRE5USfQygkdzShRN4kAdRMkb63Fxl";

    public static void main(String[] args) {
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        //System.setProperty("aip.log4j.conf", "classpath:log4j.properties");

        AipSpeech aipSpeech = new AipSpeech(APP_ID,API_KEY,SECRET_KEY);
        // 调用接口
        asr(aipSpeech);

    }

    public static void asr(AipSpeech client)
    {
        // 对本地语音文件进行识别
        String path = "/Users/wangshuohao/myhome/16k1.pcm";
        JSONObject asrRes = client.asr(path, "pcm", 16000, null);
        System.out.println(asrRes);

    }
}
